<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>write</title>
    <link rel="stylesheet" href="/bootstrap-3.3.7/dist/css/bootstrap.css">
    <link rel="stylesheet" href="../public/font">
    <link rel='stylesheet' href='/stylesheets/style.css' />
    <link rel="stylesheet" href="/stylesheets/simditor.css" />
    <link rel="stylesheet" href="/stylesheets/write.css" />
    <link rel="stylesheet" href="/stylesheets/myAlert.css">

    <script src="/javascripts/jquery.min.js"></script>
    <script src='/bootstrap-3.3.7/dist/js/bootstrap.min.js'></script>
    <script src='/javascripts/myAlert.js'></script>
    <script src="/javascripts/module.min.js"></script>
    <script src="/javascripts/hotkeys.min.js"></script>
    <script src="/javascripts/uploader.min.js"></script>
    <script src="/javascripts/simditor.min.js"></script>
  </head>

  <body>
    <div class="container-fluid">
      <div class="row">
        <div class="col-md-12 mynav">
          <nav class="navbar navbar-default">
            <div class="container">
              <!-- Brand and toggle get grouped for better mobile display -->
              <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
                  <span class="sr-only">Toggle navigation</span>
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
                  <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="/">主页</a>
              </div>

              <!-- Collect the nav links, forms, and other content for toggling -->
              <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                  <!-- <li><a href="/">新鲜事</span></a></li> -->
                  <!-- <li><a href="#">问答</a></li> -->
                  <li><a href="/yangsheng">养生</a></li>
                  <li><a href="/meishi">美食</a></li>
                  <li><a href="/hufu">护肤</a></li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                <% if(typeof(username)=='undefined') { %>
                    <li><a class="sm_a" href="/login">登录</a></li>
                    <li><a class="sm_a" href="#">注册</a></li>
                  <% } %>
                  <% if(typeof(username)!='undefined') { %>
                    <% if(username!='') { %>
                      <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><%= username %> <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                          <li><a href="/myHome">我的主页</a></li>
                          <li><a href="/write">写博客</a></li>
                          <li><a href="/setting">资料设置</a></li>
                          <li role="separator" class="divider"></li>
                          <li><a href="/exit">退出登录</a></li>
                        </ul>
                      </li>
                    <% } %>
                    <% if(username=='') { %>
                      <li><a class="sm_a" href="/login">登录</a></li>
                      <li><a class="sm_a" href="#">注册</a></li>
                    <% } %>
                   <% } %>

                </ul>
                <form class="navbar-form navbar-right">
                  <div class="form-group">
                    <input type="text" class="form-control" placeholder="Search">
                  </div>
                  <i class="glyphicon glyphicon-search mysearch"></i>
                </form>
              </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
          </nav>
        </div>
      </div>
    </div>

    <div class="container-fluid smallnav">
      <div class="row">
        <div class="col-md-12 white">
          <nav class="navbar navbar-default">
            <div class="container">

              <!-- Collect the nav links, forms, and other content for toggling -->
              <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                <ul class="nav navbar-nav">
                  <li><a href="/myHome">我的文章</a></li>
                  <li class="active"><a href="/write">写文章</a></li>
                  <li><a href="/setting">资料设置</a></li>
                </ul>
              </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
          </nav>
        </div>
      </div>
    </div>


    <section id="write">
      <div class="container">
        <div class="row">
          <div class="col-sm-3 write_left">
            <ul class="list-group">
              <li trid="1" onclick="change($(this).attr('trid'))" class="list-group-item liactive">编辑文章</li>
              <li trid="2" onclick="change($(this).attr('trid'))" class="list-group-item">文章管理</li>
              <!-- <li trid="3" onclick="change($(this).attr('trid'))" class="list-group-item">分类管理</li> -->
              <li trid="4" onclick="change($(this).attr('trid'))" class="list-group-item">评论管理</li>
            </ul>
          </div>
          <div class="col-sm-9 write_right">
            <div trid="1" class="article">
              <form action="/send_blog" method="post">
                <div class="form-group">
                    <input class="head_input" name="title" type="text" placeholder="输入文章标题">
                </div>
                <textarea id="editor" name="content" placeholder="正文内容" autofocus></textarea>
                <div class="form-group">
                <br>
                <button onClick="$.myToast('微博发布成功！')" class="btn btn-default pull-right" type="submit">发布</button>
                </div>
              </form>
            </div>
            <div  trid="2" class="article">
              <ul class="list-group">
                  <li class="list-group-item">文章管理</li>
              </ul>
              <div class="ar_list">
                <% for (var i=0; i<data.length; i++) { %>
                  <div class="list">
                    <p class="list_title"><%=data[i].title%></p>
                    <div class="btn">
                      <button class="del" onclick="del_ar(this)"><i class="glyphicon glyphicon-trash"></i>删除</button>
                      <button class="eti"><i class="glyphicon glyphicon-edit"></i>编辑</button>
                    </div>
                    
                  </div>
                <% } %>
              </div>
              <br>
              <br>
                <div class="col-sm-12 text-center">
                  <nav aria-label="Page navigation">
                    <ul class="pagination">
                      <li>
                        <a href=/?page=pre aria-label="Previous">
                          <span aria-hidden="true">&laquo;</span>
                        </a>
                      </li>
                      <% for (var i=1; i<=sumPage; i++) { %>
                        <li><a href="/?page=<%=i%>"><%= i%></a></li>
                      <% } %>
                      <li>
                        <a href="/?page=next" aria-label="Next">
                          <span aria-hidden="true">&raquo;</span>
                        </a>
                      </li>
                    </ul>
                  </nav>
                </div>
            </div>
            <!-- <div  trid="3" class="article">
              <ul class="list-group">
                  <li class="list-group-item">分类管理</li>
              </ul>
              <p> 这是分类管理的内容</p>
            </div> -->
            <div  trid="4" class="article">
              <ul class="list-group">
                  <li class="list-group-item">评论管理</li>
              </ul>
              <div class="ar_list">
                  <% for (var i=0; i<data2.length; i++) { %>
                    <div class="list">
                      <p class="list_title"><span class="name"><%=data2[i].name%></span> : <span class="title"><%=data2[i].content%></span></p>
                      
                      <div class="btn">
                        <button class="del" onclick="del_co(this)"><i class="glyphicon glyphicon-trash"></i>删除</button>
                        <button class="eti"><i class="glyphicon glyphicon-edit"></i>编辑</button>
                      </div>
                      
                    </div>
                  <% } %>
                </div>
            </div>
          </div>
        </div>
      </div>
    </section>


    <script>
    var dataflag=0;
      var editor = new Simditor({
        textarea: $('#editor')
    });

      function change(a){
        $(`.write_left li[trid = ${a}]`).addClass('liactive').siblings('li').removeClass('liactive');
        $(`.write_right>div[trid = ${a}]`).show().siblings('div').hide()
      }

      function del_ar(a){
        $(a).parent('.btn').parent('.list').hide();
        $.ajax({
          url: '/delarticle',
          method: 'post',
          dataType: 'json',
          data: {
            title: $(a).parent('.btn').siblings('.list_title').children('.title').html(),
          },
          success:function(res){
            console.log(res)
          }
        })
        
      }

      function del_co(a){
        $.ajax({
          url: '/del_mycomment',
          method: 'post',
          dataType: 'json',
          data: {
            content: $(a).parent('.btn').siblings('.list_title').children('.title').html(),
            name:  $(a).parent('.btn').siblings('.list_title').children('.name').html()
          },
          success:function(res){
              $(a).parent('.btn').parent('.list').hide();
          }
        })
        
      }

    </script>

  </body>
</html>
